package com.ytjj.qmyx.admin.service.impl;

import com.ytjj.qmyx.admin.dao.BrandDao;
import com.ytjj.qmyx.admin.model.request.BrandToSpecialRequest;
import com.ytjj.qmyx.admin.service.BrandService;
import com.ytjj.qmyx.mall.mapper.SpecialBrandMapper;
import com.ytjj.qmyx.mall.model.Brand;
import com.ytjj.qmyx.mall.model.Special;
import com.ytjj.qmyx.mall.model.SpecialBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 *
 *
 * @Version: 1.0
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandDao brandDao;
    @Resource
    private SpecialBrandMapper specialBrandMapper;

    @Override
    public List<Brand> getBrandNameList() {
        return brandDao.getBrandNameList();
    }

    @Override
    public List<Special> getSpecialList() {
        return brandDao.getSpecialList();
    }

    @Override
    public void addBrandToSpecial(BrandToSpecialRequest brandToSpecialRequest) {
        String brandIds = brandToSpecialRequest.getBrandIds();
        String[] ids = brandIds.split(",");
        for (String idStr : ids) {
            int id = Integer.valueOf(idStr);
            SpecialBrand specialBrand = new SpecialBrand();
            specialBrand.setSpecialId(brandToSpecialRequest.getSpecialId());
            specialBrand.setBankerId(id);
            specialBrand.setStatus(1);
            specialBrand.setCreateTime(new Date());
            specialBrandMapper.insertSelective(specialBrand);
        }
    }

    @Override
    public void addBankerToSpecial(BrandToSpecialRequest brandToSpecialRequest) {
        SpecialBrand specialBrand = new SpecialBrand();
        specialBrand.setSpecialId(brandToSpecialRequest.getSpecialId());
        specialBrand.setBankerId(brandToSpecialRequest.getBankerId());
        specialBrand.setStatus(1);
        specialBrand.setCreateTime(new Date());
        specialBrandMapper.insertSelective(specialBrand);
    }
}
